from fastapi.responses import JSONResponse
from pydantic import conint

from common.base.base_routers import get_custom_router
from services.relays_module.api import RelaysModuleApi
from services.relays_module.schemas.configs import RmConfig
from settings import settings

rm_api = RelaysModuleApi()
relays_module_router = get_custom_router(rm_api, prefix='/relays_module', tags=['relays_module'])


@relays_module_router.post('/set-configure/', response_class=JSONResponse)
async def set_configure(index: conint(ge=0, lt=settings.SERVICES_RELAYS_NUMBER), config: RmConfig):
    return await rm_api.set_configure(index, config)


@relays_module_router.get('/get-configure/', response_class=JSONResponse)
async def get_configure(index: conint(ge=0, lt=settings.SERVICES_RELAYS_NUMBER)):
    return await rm_api.get_configure(index)


@relays_module_router.get('/get-telemetry/', response_class=JSONResponse)
async def get_telemetry(index: conint(ge=0, lt=settings.SERVICES_RELAYS_NUMBER)):
    return await rm_api.get_telemetry(index)
